package com.etc.service.impl;

import com.etc.dao.HistoryMapper;
import com.etc.dao.PatientMapper;
import com.etc.entity.History;
import com.etc.entity.Patient;
import com.etc.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

@Service
@Transactional
public class HistoryServiceImpl implements HistoryService {

    @Autowired
    private HistoryMapper historyMapper;

    @Autowired
    private PatientMapper patientMapper;


    @Override
    public boolean deleteHistoryDetail(String historyId) {
        int i = historyMapper.deleteHistoryDetail(historyId);
        return i>0;
    }

    @Override
    public boolean insertHistoryDetail(String patientName, String doctorId,String content) {
        Patient patient=new Patient();
        patient.setPatientName(patientName);
        List<Patient> patientList = patientMapper.findSelective(patient);
        String patientId = patientList.get(0).getPatientId();
        History history=new History();
        history.setPatientId(patientId);
        history.setHistoryId(UUID.randomUUID().toString().replace("-",""));
        history.setDoctorId(doctorId);
        history.setContent(content);
        int i = historyMapper.insertHistoryDetail(history);
        return i>0;
    }

    @Override
    public boolean updateHistoryDetail(String historyId,String historyContent) {
        History history=new History();
        history.setHistoryId(historyId);
        history.setContent(historyContent);
        int i = historyMapper.updateHistoryDetail(history);
        return i>0;
    }
}
